import styles from './index.less';
import { useEffect, useState } from 'react';
import { allGet } from '@/services/pc';
import { ISCLOSEAPPLYTEACHERSUCCESS } from '@/common/const';
import storage from '@/utils/storage';
import { useModel } from 'umi';
import moment from 'moment';
const Index = () => {
  const [show, setShow] = useState(false);
  const { userInfo } = useModel('user');
  const init = async () => {
    const response = await allGet({ params: { mod: 'teacher', do: 'add', version: 'pc1.0' } });
    const flag = storage.get(ISCLOSEAPPLYTEACHERSUCCESS);
    const applyTime = userInfo?.teacher?.dateline * 1;
    const isApplynew = moment('2025-1-31').unix();
    if (response?.data?.teacher?.status == 0 && flag !== true && applyTime >= isApplynew) {
      setShow(true);
    } else {
      setShow(false);
    }
  };
  useEffect(() => {
    if (!userInfo.uid) return;
    init();
  }, [userInfo]);
  const close = () => {
    storage.set(ISCLOSEAPPLYTEACHERSUCCESS, true);
    setShow(false);
  };

  const ziliao = () => {
    close();
    window.location.href = '/lecturer?index=5';
  };
  return (
    <div>
      {show && (
        <>
          <div className={styles.mask} />
          <div className={styles.main}>
            <div className={styles.close} onClick={close} />
            <div className={styles.bgtop} />
            <div className={styles.title}>
              <div className={styles.icon} />
              <div className={styles.text}>恭喜您已经成为CGJOY官方讲师</div>
            </div>
            <div className={styles.button} onClick={ziliao}>
              填写合作资料
            </div>
            <div className={styles.tips}>将来可在首页的右上角的 [上传课程] 按钮进行发布课程</div>
            <div className={styles.bgbottom} />
          </div>
        </>
      )}
    </div>
  );
};

export default Index;
